
import P01 from './P01';
import P02 from './P02';
import P03 from './P03';
import P04 from './P04';
import P05 from './P05';
import P06 from './P06';


import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';

import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
export default async function a023(fd: IFeidaoAiBrowserComponent, shezhi: { role_no: string, role_allot_id: string, group_id: string }, no: number, args: string[]) {
	// 渲染
	const productid = get(fd, 'productid');
	let role_allot_id = shezhi.role_allot_id;
	const group_id = shezhi.group_id;
	const role_no = get(fd, 'role_no');

	if (no === 1) {

		const page_no = 1;
		const page_size = get(fd, 'page_size') as number;
		const query = { productid, role_no, page_no, page_size };
		show_loading();
		const res = await nodejs<{ dataArray: object[], count: number, page_no: number, page_size: number }>('roler/zj-000004/s001', query);
		hide_loading();
		if (res.dataArray.length === 0) {
			render(fd, '', P01, 'P01', 'inner');
			fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P05"]').innerHTML = '';
			render(fd, '', P04, 'P04', 'inner');
		} else {
			render(fd, res.dataArray, P01, 'P01', 'inner');
			res.page_no = page_no;
			res.page_size = page_size;
			fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P04"]').innerHTML = '';
			render(fd, res, P05, 'P05', 'inner');
		}
		render(fd, '', P02, 'P02', 'inner');
		render(fd, '', P03, 'P03', 'inner');
		render(fd, '', P06, 'P06', 'inner');
	} else if (no === 2) {
		role_allot_id = String(shezhi);
		const query = { productid, role_allot_id };
		show_loading();
		const data = await nodejs<{ length: number }>('roler/zj-000004/s021', query);
		hide_loading();
		if (data.length === 0) {
			render(fd, '', P02, 'P02', 'inner');
		} else {
			render(fd, data, P02, 'P02', 'inner');
		}
		render(fd, '', P03, 'P03', 'inner');
		remove(fd, 'allot_group');
		if (args) {
			const ids = args;
			ids.map((v: string) => {
				if (v) {
					const node = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id4="' + v + '"]');
					if (node) {
						node.checked = true;
					}
				}
			});
		}
		render(fd, '', P06, 'P06', 'inner');
	} else {

		show_loading();
		const res = await nodejs<{ dataArray: object[], count: number }>('roler/zj-000004/s022', { productid, role_allot_id, group_id });
		hide_loading();
		if (res.count === 0) {
			render(fd, '', P03, 'P03', 'inner');
		} else {
			const data = res.dataArray.map((v) => {
				return { ...v, v: JSON.stringify(v) };
			});
			render(fd, data, P03, 'P03', 'inner');
		}
		const _id = get(fd, 'role_allot_id') as string;
		const query = {
			productid, role_allot_id: _id, group_id
		};
		fire('zj-000004', 'eu-013', query, false, false);
	}
}
